package com.group.eams.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.AnnounceMannageQueryDto;
import com.group.eams.pojo.entity.AnnounceMannage;
import com.group.eams.pojo.vo.AnnounceMannageListVo;
import com.group.eams.service.AnnounceMannageService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import javafx.geometry.Pos;
import org.apache.commons.collections4.Get;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 公告管理(AnnounceMannage)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@RestController
@ResponseBody
@RequestMapping("/announceMannage")
public class AnnounceMannageController  {
    /**
     * 服务对象
     */
    @Autowired
    private AnnounceMannageService announceMannageService;

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public Result list ( @RequestBody AnnounceMannageQueryDto announceMannageQueryDto){

        //1.准备分页条件
        Page page=new Page<>(announceMannageQueryDto.getPage(),announceMannageQueryDto.getLimit());

        //2.查询分页数据
        Page<AnnounceMannageListVo> announceMannageByQueryDto = announceMannageService.findAnnounceMannageByQueryDto(page, announceMannageQueryDto);

        //返回结果
        return Result.buildSuccess(announceMannageByQueryDto.getTotal(),announceMannageByQueryDto.getRecords());

    }
    @RequestMapping(value = "/find",method = RequestMethod.GET)
    public Result  find(@RequestParam Long id){
        AnnounceMannage announceMannage = announceMannageService.getById(id);
        return Result.buildSuccess(announceMannage);
    }

    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result  findAll( ){
        List<AnnounceMannage> list = announceMannageService.list();

        return Result.buildSuccess(list);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result add(@RequestBody AnnounceMannage announceMannage){
        boolean result = announceMannageService.save(announceMannage);

        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result update(@RequestBody AnnounceMannage announceMannage){
        boolean result = announceMannageService.updateById(announceMannage);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public Result delete(@RequestParam Long id){

        boolean result = announceMannageService.removeById(id);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    public Result batchDelete(@RequestBody BatchDeleteDto batchDeleteDto){

        boolean result = announceMannageService.removeByIds(batchDeleteDto.getIds());
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }
}

